
import com.sun.mail.pop3.POP3Store;
import java.io.IOException;
import static java.lang.System.out;
import java.util.Properties;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import static test.EmailReceiveTest.receiveEmail;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Lucas Nguyen
 */
public class NewClass {
    public static void main(String[] args) throws NoSuchProviderException, MessagingException {

		String mailPop3Host = "nhom5.no-ip.org";
		String mailStoreType = "pop3";
		String mailUser = "hoangthach@nhom5.no-ip.org";
		String mailPassword = "1";
                receiveEmail(mailPop3Host, mailStoreType, mailUser, mailPassword);
    }
    
           public static void receiveEmail(String pop3Host, String storeType, String user, String password) {

		try {
			Properties properties = new Properties();
			properties.put("mail.pop3.host", pop3Host);
			Session emailSession = Session.getDefaultInstance(properties);

			POP3Store emailStore = (POP3Store) emailSession.getStore(storeType);
                                
                        emailStore.connect(pop3Host, user, password);
                        out.println("Kết nối thành công...");
			Folder emailFolder = emailStore.getFolder("INBOX");
                        
			//emailFolder.open(Folder.READ_ONLY);
                      //  out.println("Đang nạp hộp thư đến...");
			//Message[] messages = emailFolder.getMessages();
                      //  System.out.print(messages.length);
                        
			

			emailFolder.close(false);
			emailStore.close();
		} catch (NoSuchProviderException e) {
			e.printStackTrace();
		} catch (MessagingException e) {
			e.printStackTrace();
                     
		}
                
                
		}
}
